#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int log2(int n)
{
	int ans = 0;
	while ((1 << ans) < (n >> 1)) {
		ans++;
	}
	return ans;
}

void dfs(vector<vector<int>> &tree, vector<int> &deep, vector<vector<int>> &st, int power, int u, int f)
{
	deep[u] = deep[f] + 1;
	st[u][0] = f;
	for (int i = 1; i <= power; i++) {
		st[u][i] = st[st[u][i - 1]][i - 1];
	}
	for (auto v : tree[u]) {
		if (v != f) {
			dfs(tree, deep, st, power, v, u);
		}
	}
}

int lca(vector<vector<int>> &tree, vector<int> &deep, vector<vector<int>> &st, int power, int a, int b)
{
	if (deep[a] < deep[b]) {
		swap(a, b);
	}

	int k = deep[a] - deep[b];
	for (int p = power; p >= 0; p--) {
		if (deep[st[a][p]] >= deep[b]) {
			a = st[a][p];
		}
	}

	if (a == b) {
		return a;
	}

	// for (int i = 0; i <= power; i++) {
	// 	if (st[a][i] != st[b][i]) {
	// 		a = st[a][i];
	// 		b = st[b][i];
	// 	}
	// }

	for (int i = power; i >= 0; i--) {
		if (st[a][i] != st[b][i]) {
			a = st[a][i];
			b = st[b][i];
		}
	}

	return st[a][0];
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n = 0, m = 0, s = 0;
	cin >> n >> m >> s;
	vector<vector<int>> tree(n + 1);
	vector<int> deep(n + 1, 0);

	for (int i = 0, u, v; i < n - 1; i++) {
		cin >> u >> v;
		tree[u].push_back(v);
		tree[v].push_back(u);
	}

	int power = log2(n);
	vector<vector<int>> st(n + 1, vector<int>(power + 1, 0));
	dfs(tree, deep, st, power, s, s);

	for (int i = 0, a, b; i < m; i++) {
		cin >> a >> b;
		cout << lca(tree, deep, st, power, a, b) << '\n';
	}

	return 0;
}